package com.bodacn.keypoint.adapter;

import android.content.Context;
import android.os.Build;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.RequiresApi;

import com.bodacn.keypoint.R;
import com.bodacn.keypoint.bean.ClothPieceCheckRight;

import java.text.DecimalFormat;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;


public class ClothPieceSearchRightLvAdapter extends BaseAdapter {

    private LayoutInflater inflater;
    private Context mContext;
    private List<ClothPieceCheckRight> list;
    private DecimalFormat fnum;

    public ClothPieceSearchRightLvAdapter(List<ClothPieceCheckRight> list, Context context) {
        this.inflater = LayoutInflater.from(context);
        this.mContext = context;
        this.list = list;
        fnum = new DecimalFormat("##0.0");
    }


    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @RequiresApi(api = Build.VERSION_CODES.M)
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        final ViewHolder viewHodler;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.item_cloth_piece_check_right, parent, false);
            viewHodler = new ViewHolder(convertView);
            convertView.setTag(viewHodler);
        } else {
            viewHodler = (ViewHolder) convertView.getTag();
        }
        if (list.size() > 0) {
            ClothPieceCheckRight clothPieceCheckRight = list.get(position);
            viewHodler.tvPartName.setText(clothPieceCheckRight.getPartName());

            viewHodler.tvNormalH.setText(clothPieceCheckRight.getStandSizeH());
            viewHodler.tvNormalV.setText(clothPieceCheckRight.getStandSizeV());

            viewHodler.tvBeforeH.setText(clothPieceCheckRight.getBeforeSizeH());
            viewHodler.tvBeforeV.setText(clothPieceCheckRight.getBeforeSizeV());

            viewHodler.tvCheckresult.setText(clothPieceCheckRight.getResult());

            viewHodler.tvScaleH.setText(clothPieceCheckRight.getScaleH());
            viewHodler.tvScaleV.setText(clothPieceCheckRight.getScaleV());

            viewHodler.tvWeihtV.setText(clothPieceCheckRight.getRealSizeV());
            viewHodler.edWeightH.setText(clothPieceCheckRight.getRealSizeH());

            if (clothPieceCheckRight.getResult().equals("1")){
                viewHodler.tvCheckresult.setBackgroundColor(mContext.getResources().getColor(R.color.green));
                viewHodler.tvCheckresult.setText("合格");
            }else {
                viewHodler.tvCheckresult.setBackgroundColor(mContext.getResources().getColor(R.color.red));
                viewHodler.tvCheckresult.setText("不合格");
            }

        }

        return convertView;
    }



    class ViewHolder {
        @BindView(R.id.tv_PartName)
        TextView tvPartName;
        @BindView(R.id.tv_normal_v)
        TextView tvNormalV;
        @BindView(R.id.tv_normal_h)
        TextView tvNormalH;
        @BindView(R.id.tv_scale_v)
        TextView tvScaleV;
        @BindView(R.id.tv_scale_h)
        TextView tvScaleH;
        @BindView(R.id.tv_before_v)
        TextView tvBeforeV;
        @BindView(R.id.tv_before_h)
        TextView tvBeforeH;
        @BindView(R.id.tv_weiht_v)
        TextView tvWeihtV;
        @BindView(R.id.ed_weight_h)
        TextView edWeightH;
        @BindView(R.id.tv_checkresult)
        TextView tvCheckresult;
        @BindView(R.id.mylistitem)
        LinearLayout mylistitem;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
